package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.query.TravelQuery;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.domain.*;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.*;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 大攻略
 */
@RestController
@RequestMapping("strategies")
public class StrategyController {

    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private IStrategyCatalogService strategyCatalogService;

    @Autowired
    private IStrategyDetailService strategyDetailService;

    @Autowired
    private ITravelService travelService;

    @Autowired
    private IStrategyReviewService strategyReviewService;

    /**
     * 查询大攻略中推荐的信息
     *
     * @return
     */
    @GetMapping
    public JSONResult select() {
        List<Strategy> strategies = strategyService.selectByState(Strategy.STATE_HOT);
        JSONResult jsonResult = new JSONResult();
        jsonResult.setResult(strategies);
        return jsonResult;
    }

    /**
     * 根据id获取大攻略对象
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Strategy getById(@PathVariable Long id) {
        return strategyService.getById(id);
    }

    /**
     * 根据大攻略的id获取攻略分类数据集合
     * @param id
     * @return
     */
    @GetMapping("/{id}/catalogs")
    public List<StrategyCatalog> listCatalogByStrategyId(@PathVariable Long id) {
        return strategyCatalogService.listByStrategyId(id);
    }

    /**
     * 根据攻略文章id查找攻略文章内容
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public StrategyDetail getDetailsById(@PathVariable Long id) {
        return strategyDetailService.getDetailsById(id);
    }

    @GetMapping("/{id}/travels")
    public List<Travel> getTravelsByStrategyId(@PathVariable("id") Long id) {
        List<Travel> travels = travelService.getTravelsByStrategyId(id);
        return travels;
    }

    /*@GetMapping("/{id}/catalogs")
    public List<StrategyCatalog> listCatalogByStrategyId2(@PathVariable Long id) {
        return strategyCatalogService.listByStrategyId(id);
    }*/

    // 攻略点评分页
    @GetMapping("/{sid}/reviews")
    public PageInfo<StrategyReview> listAllReviews(@PathVariable Long sid, QueryObject qo){
        return strategyReviewService.query(sid, qo);
    }

    // 攻略点评分页
    @GetMapping("/{sid}/allreviews")
    public List<StrategyReview> listAllReviews(@PathVariable Long sid){
        return strategyReviewService.listAll(sid);
    }

    // 新增攻略点评
    @PostMapping("/addreviews")
    public JSONResult save(StrategyReview strategyReview){
        //strategyReview.getStrategy().setId(sid);
        strategyReviewService.save(strategyReview);
        return new JSONResult();
    }
}
